
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>推导 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="strings.html" />
    
    
    <link rel="prev" href="testing.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">第一部分：基础</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="basics.html">
            
                <a href="basics.html">
            
                    
                    基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="collections.html">
            
                <a href="collections.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="enum.html">
            
                <a href="enum.html">
            
                    
                    Enum 模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="pattern-matching.html">
            
                <a href="pattern-matching.html">
            
                    
                    模式匹配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="control-structures.html">
            
                <a href="control-structures.html">
            
                    
                    控制语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="functions.html">
            
                <a href="functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="pipe-operator.html">
            
                <a href="pipe-operator.html">
            
                    
                    管道操作符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="modules.html">
            
                <a href="modules.html">
            
                    
                    模块(Module)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="mix.html">
            
                <a href="mix.html">
            
                    
                    Mix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="sigils.html">
            
                <a href="sigils.html">
            
                    
                    魔符(Sigil)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="documentation.html">
            
                <a href="documentation.html">
            
                    
                    文档模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="testing.html">
            
                <a href="testing.html">
            
                    
                    测试
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.14" data-path="comprehensions.html">
            
                <a href="comprehensions.html">
            
                    
                    推导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="strings.html">
            
                <a href="strings.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="date-time.html">
            
                <a href="date-time.html">
            
                    
                    日期和时间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="mix-tasks.html">
            
                <a href="mix-tasks.html">
            
                    
                    自定义Mix任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="iex-helpers.html">
            
                <a href="iex-helpers.html">
            
                    
                    IEx辅助函数
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第二部分：高级</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../advanced/erlang.html">
            
                <a href="../advanced/erlang.html">
            
                    
                    和Erlang互操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../advanced/error-handling.html">
            
                <a href="../advanced/error-handling.html">
            
                    
                    错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../advanced/escripts.html">
            
                <a href="../advanced/escripts.html">
            
                    
                    可执行文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../advanced/concurrency.html">
            
                <a href="../advanced/concurrency.html">
            
                    
                    并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../advanced/otp-concurrency.html">
            
                <a href="../advanced/otp-concurrency.html">
            
                    
                    OTP并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../advanced/otp-supervisors.html">
            
                <a href="../advanced/otp-supervisors.html">
            
                    
                    OTP Supervisors
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../advanced/otp-distribution.html">
            
                <a href="../advanced/otp-distribution.html">
            
                    
                    OTP 分布式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="../advanced/metaprogramming.html">
            
                <a href="../advanced/metaprogramming.html">
            
                    
                    元编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="../advanced/umbrella-projects.html">
            
                <a href="../advanced/umbrella-projects.html">
            
                    
                    Umbrella Projects
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="../advanced/typespec.html">
            
                <a href="../advanced/typespec.html">
            
                    
                    Specifications and types
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="../advanced/behaviours.html">
            
                <a href="../advanced/behaviours.html">
            
                    
                    行为
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="../advanced/gen-stage.html">
            
                <a href="../advanced/gen-stage.html">
            
                    
                    GenStage
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="../advanced/protocols.html">
            
                <a href="../advanced/protocols.html">
            
                    
                    协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="../advanced/nerves.html">
            
                <a href="../advanced/nerves.html">
            
                    
                    Nerves
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第三部分：ECTO</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../ecto/basics.html">
            
                <a href="../ecto/basics.html">
            
                    
                    Basics
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../ecto/changesets.html">
            
                <a href="../ecto/changesets.html">
            
                    
                    Changesets
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../ecto/associations.html">
            
                <a href="../ecto/associations.html">
            
                    
                    关联关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../ecto/querying.html">
            
                <a href="../ecto/querying.html">
            
                    
                    查询
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第四部分：专题</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../specifics/plug.html">
            
                <a href="../specifics/plug.html">
            
                    
                    Plug
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../specifics/eex.html">
            
                <a href="../specifics/eex.html">
            
                    
                    嵌入的 Elixir(EEx)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../specifics/ets.html">
            
                <a href="../specifics/ets.html">
            
                    
                    Erlang 项式存储(ETS)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../specifics/mnesia.html">
            
                <a href="../specifics/mnesia.html">
            
                    
                    Mnesia 数据库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../specifics/debugging.html">
            
                <a href="../specifics/debugging.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第五部分：程序库</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../libraries/guardian.html">
            
                <a href="../libraries/guardian.html">
            
                    
                    Guardian(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../libraries/poolboy.html">
            
                <a href="../libraries/poolboy.html">
            
                    
                    Poolboy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../libraries/benchee.html">
            
                <a href="../libraries/benchee.html">
            
                    
                    Benchee
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../libraries/bypass.html">
            
                <a href="../libraries/bypass.html">
            
                    
                    Bypass
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../libraries/distillery.html">
            
                <a href="../libraries/distillery.html">
            
                    
                    Distillery(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../libraries/stream-data.html">
            
                <a href="../libraries/stream-data.html">
            
                    
                    StreamData
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >推导</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x5728; Elixir &#x4E2D;&#xFF0C;&#x5217;&#x8868;&#x63A8;&#x5BFC;&#x662F;&#x5FAA;&#x73AF;&#x904D;&#x5386;&#x679A;&#x4E3E;&#x503C;&#x7684;&#x8BED;&#x6CD5;&#x7CD6;&#x3002;&#x8FD9;&#x8282;&#x8BFE;&#xFF0C;&#x6211;&#x4EEC;&#x5C31;&#x6765;&#x770B;&#x770B;&#x5982;&#x4F55;&#x4F7F;&#x7528;&#x63A8;&#x5BFC;&#x5F0F;&#x8FDB;&#x884C;&#x904D;&#x5386;&#x3002;</p>
<h2 id="&#x57FA;&#x7840;">&#x57FA;&#x7840;</h2>
<p>&#x5F88;&#x591A;&#x65F6;&#x5019;&#xFF0C;&#x4F7F;&#x7528;&#x63A8;&#x5BFC;&#x80FD;&#x4F7F;&#x7528;&#x66F4;&#x7B80;&#x6D01;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x6765;&#x904D;&#x5386; Enum &#x548C; Stream&#x3002;&#x6211;&#x4EEC;&#x5148;&#x770B;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x4F8B;&#x5B50;&#xFF0C;&#x7136;&#x540E;&#x5206;&#x6790;&#x5B83;&#x7684;&#x7ED3;&#x6784;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; list = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]
iex&gt; <span class="hljs-keyword">for</span> x &lt;- list, <span class="hljs-symbol">do:</span> x*x
[<span class="hljs-number">1</span>, <span class="hljs-number">4</span>, <span class="hljs-number">9</span>, <span class="hljs-number">16</span>, <span class="hljs-number">25</span>]
</code></pre>
<p>&#x9996;&#x5148;&#x6CE8;&#x610F; <code>for</code> &#x548C;&#x751F;&#x6210;&#x5668;&#x7684;&#x4F7F;&#x7528;&#x3002;&#x4EC0;&#x4E48;&#x662F;&#x201C;&#x751F;&#x6210;&#x5668;&#x201D;&#x5462;&#xFF1F;&#x751F;&#x6210;&#x5668;&#x5C31;&#x662F;&#x4E0A;&#x9762; <code>x &lt;- [1, 2, 3, 4]</code> &#x8868;&#x8FBE;&#x5F0F;&#x90E8;&#x5206;&#xFF0C;&#x5B83;&#x4EEC;&#x7528;&#x6765;&#x751F;&#x6210;&#x4E0B;&#x4E00;&#x4E2A;&#x503C;&#x3002;</p>
<p>&#x5E78;&#x8FD0;&#x7684;&#x662F;&#xFF0C;&#x63A8;&#x5BFC;&#x5F0F;&#x4E0D;&#x4EC5;&#x53EF;&#x4EE5;&#x7528;&#x5728;&#x5217;&#x8868;&#x4E0A;&#xFF0C;&#x5B83;&#x4EEC;&#x5B9E;&#x9645;&#x4E0A;&#x53EF;&#x7528;&#x5728;&#x4EFB;&#x4F55;&#x53EF;&#x904D;&#x5386;&#x7C7B;&#x578B;&#x3002;</p>
<pre><code class="lang-elixir"><span class="hljs-comment"># &#x5173;&#x952E;&#x5B57;&#x5217;&#x8868;</span>
iex&gt; <span class="hljs-keyword">for</span> {_key, val} &lt;- [<span class="hljs-symbol">one:</span> <span class="hljs-number">1</span>, <span class="hljs-symbol">two:</span> <span class="hljs-number">2</span>, <span class="hljs-symbol">three:</span> <span class="hljs-number">3</span>], <span class="hljs-symbol">do:</span> val
[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]

<span class="hljs-comment"># &#x6620;&#x5C04;</span>
iex&gt; <span class="hljs-keyword">for</span> {k, v} &lt;- %{<span class="hljs-string">&quot;a&quot;</span> =&gt; <span class="hljs-string">&quot;A&quot;</span>, <span class="hljs-string">&quot;b&quot;</span> =&gt; <span class="hljs-string">&quot;B&quot;</span>}, <span class="hljs-symbol">do:</span> {k, v}
[{<span class="hljs-string">&quot;a&quot;</span>, <span class="hljs-string">&quot;A&quot;</span>}, {<span class="hljs-string">&quot;b&quot;</span>, <span class="hljs-string">&quot;B&quot;</span>}]

<span class="hljs-comment"># &#x4E8C;&#x8FDB;&#x5236;</span>
iex&gt; <span class="hljs-keyword">for</span> &lt;&lt;c &lt;- <span class="hljs-string">&quot;hello&quot;</span>&gt;&gt;, <span class="hljs-symbol">do:</span> &lt;&lt;c&gt;&gt;
[<span class="hljs-string">&quot;h&quot;</span>, <span class="hljs-string">&quot;e&quot;</span>, <span class="hljs-string">&quot;l&quot;</span>, <span class="hljs-string">&quot;l&quot;</span>, <span class="hljs-string">&quot;o&quot;</span>]
</code></pre>
<p>&#x548C; Elixir &#x5F88;&#x591A;&#x4E1C;&#x897F;&#x4E00;&#x6837;&#xFF0C;&#x751F;&#x6210;&#x5668;&#x4E5F;&#x4F9D;&#x9760;&#x6A21;&#x5F0F;&#x5339;&#x914D;&#x6765;&#x6BD4;&#x8F83;&#x5B83;&#x4EEC;&#x7684;&#x8F93;&#x5165;&#x548C;&#x5DE6;&#x8FB9;&#x7684;&#x53D8;&#x91CF;&#x3002;&#x5982;&#x679C;&#x5339;&#x914D;&#x6CA1;&#x6709;&#x627E;&#x5230;&#xFF0C;&#x5BF9;&#x5E94;&#x7684;&#x503C;&#x5C31;&#x76F4;&#x63A5;&#x88AB;&#x5FFD;&#x7565;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-keyword">for</span> {<span class="hljs-symbol">:ok</span>, val} &lt;- [<span class="hljs-symbol">ok:</span> <span class="hljs-string">&quot;Hello&quot;</span>, <span class="hljs-symbol">error:</span> <span class="hljs-string">&quot;Unknown&quot;</span>, <span class="hljs-symbol">ok:</span> <span class="hljs-string">&quot;World&quot;</span>], <span class="hljs-symbol">do:</span> val
[<span class="hljs-string">&quot;Hello&quot;</span>, <span class="hljs-string">&quot;World&quot;</span>]
</code></pre>
<p>&#x4E5F;&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x751F;&#x6210;&#x5668;&#xFF0C;&#x8FBE;&#x5230;&#x7C7B;&#x4F3C;&#x5D4C;&#x5957;&#x5FAA;&#x73AF;&#x7684;&#x6548;&#x679C;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; list = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
iex&gt; <span class="hljs-keyword">for</span> n &lt;- list, times &lt;- <span class="hljs-number">1</span>..n <span class="hljs-keyword">do</span>
...&gt;   String.duplicate(<span class="hljs-string">&quot;*&quot;</span>, times)
...&gt; <span class="hljs-keyword">end</span>
[<span class="hljs-string">&quot;*&quot;</span>, <span class="hljs-string">&quot;*&quot;</span>, <span class="hljs-string">&quot;**&quot;</span>, <span class="hljs-string">&quot;*&quot;</span>, <span class="hljs-string">&quot;**&quot;</span>, <span class="hljs-string">&quot;***&quot;</span>, <span class="hljs-string">&quot;*&quot;</span>, <span class="hljs-string">&quot;**&quot;</span>, <span class="hljs-string">&quot;***&quot;</span>, <span class="hljs-string">&quot;****&quot;</span>]
</code></pre>
<p>&#x4E3A;&#x4E86;&#x66F4;&#x6E05;&#x6670;&#x5730;&#x5C55;&#x793A;&#x5FAA;&#x73AF;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x6211;&#x4EEC;&#x7528; <code>IO.puts</code> &#x6765;&#x6253;&#x5370;&#x51FA;&#x751F;&#x6210;&#x7684;&#x4E24;&#x4E2A;&#x503C;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-keyword">for</span> n &lt;- list, times &lt;- <span class="hljs-number">1</span>..n, <span class="hljs-symbol">do:</span> IO.puts <span class="hljs-string">&quot;<span class="hljs-subst">#{n}</span> - <span class="hljs-subst">#{times}</span>&quot;</span>
<span class="hljs-number">1</span> - <span class="hljs-number">1</span>
<span class="hljs-number">2</span> - <span class="hljs-number">1</span>
<span class="hljs-number">2</span> - <span class="hljs-number">2</span>
<span class="hljs-number">3</span> - <span class="hljs-number">1</span>
<span class="hljs-number">3</span> - <span class="hljs-number">2</span>
<span class="hljs-number">3</span> - <span class="hljs-number">3</span>
<span class="hljs-number">4</span> - <span class="hljs-number">1</span>
<span class="hljs-number">4</span> - <span class="hljs-number">2</span>
<span class="hljs-number">4</span> - <span class="hljs-number">3</span>
<span class="hljs-number">4</span> - <span class="hljs-number">4</span>
</code></pre>
<p>&#x5217;&#x8868;&#x63A8;&#x5BFC;&#x5F0F;&#x53EA;&#x662F;&#x8BED;&#x6CD5;&#x7CD6;&#xFF0C;&#x5E94;&#x8BE5;&#x7528;&#x5728;&#x9002;&#x5F53;&#x7684;&#x5730;&#x65B9;&#x3002;</p>
<h2 id="&#x8FC7;&#x6EE4;&#x5668;&#xFF08;filters&#xFF09;">&#x8FC7;&#x6EE4;&#x5668;&#xFF08;filters&#xFF09;</h2>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x628A;&#x8FC7;&#x6EE4;&#x5668;&#x60F3;&#x8C61;&#x6210;&#x63A8;&#x5BFC;&#x5F0F;&#x7684;&#x54E8;&#x5175;&#xFF08;guard&#xFF09;&#xFF0C;&#x5982;&#x679C;&#x88AB;&#x8FC7;&#x6EE4;&#x7684;&#x503C;&#x8FD4;&#x56DE;&#x662F; <code>false</code> &#x6216;&#x8005; <code>nil</code>&#xFF0C;&#x90A3;&#x5B83;&#x5C31;&#x4E0D;&#x4F1A;&#x51FA;&#x73B0;&#x5728;&#x6700;&#x7EC8;&#x7684;&#x5217;&#x8868;&#x91CC;&#x3002;&#x6BD4;&#x5982;&#x53EF;&#x4EE5;&#x5FAA;&#x73AF;&#x67D0;&#x4E2A;&#x8303;&#x56F4;&#x7684;&#x503C;&#xFF0C;&#x4F46;&#x662F;&#x53EA;&#x7ED9;&#x51FA;&#x5076;&#x6570;&#x3002;&#x6211;&#x4EEC;&#x4F7F;&#x7528; <code>Integer</code> &#x6A21;&#x5757;&#x63D0;&#x4F9B;&#x7684; <code>is_even/1</code> &#x51FD;&#x6570;&#x6765;&#x68C0;&#x67E5;&#x67D0;&#x4E2A;&#x503C;&#x662F;&#x5426;&#x4E3A;&#x5076;&#x6570;&#xFF1A;</p>
<pre><code class="lang-elixir">import Integer
iex&gt; <span class="hljs-keyword">for</span> x &lt;- <span class="hljs-number">1</span>..<span class="hljs-number">10</span>, is_even(x), <span class="hljs-symbol">do:</span> x
[<span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>, <span class="hljs-number">8</span>, <span class="hljs-number">10</span>]
</code></pre>
<p>&#x548C;&#x751F;&#x6210;&#x5668;&#x4E00;&#x6837;&#xFF0C;&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x8FC7;&#x6EE4;&#x5668;&#x3002;&#x6211;&#x4EEC;&#x4FEE;&#x6539;&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#xFF0C;&#x53EA;&#x8FD4;&#x56DE;&#x6240;&#x6709;&#x662F;&#x5076;&#x6570;&#x5E76;&#x4E14;&#x80FD;&#x88AB; 3 &#x6574;&#x6570;&#x7684;&#x503C;&#xFF1A;</p>
<pre><code class="lang-elixir">import Integer
iex&gt; <span class="hljs-keyword">for</span> x &lt;- <span class="hljs-number">1</span>..<span class="hljs-number">100</span>,
...&gt;   is_even(x),
...&gt;   rem(x, <span class="hljs-number">3</span>) == <span class="hljs-number">0</span>, <span class="hljs-symbol">do:</span> x
[<span class="hljs-number">6</span>, <span class="hljs-number">12</span>, <span class="hljs-number">18</span>, <span class="hljs-number">24</span>, <span class="hljs-number">30</span>, <span class="hljs-number">36</span>, <span class="hljs-number">42</span>, <span class="hljs-number">48</span>, <span class="hljs-number">54</span>, <span class="hljs-number">60</span>, <span class="hljs-number">66</span>, <span class="hljs-number">72</span>, <span class="hljs-number">78</span>, <span class="hljs-number">84</span>, <span class="hljs-number">90</span>, <span class="hljs-number">96</span>]
</code></pre>
<h2 id="&#x4F7F;&#x7528;-into">&#x4F7F;&#x7528; <code>:into</code></h2>
<p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x60F3;&#x751F;&#x6210;&#x7684;&#x4E0D;&#x662F;&#x5217;&#x8868;&#x5462;&#xFF1F;<code>:into</code> &#x9009;&#x9879;&#x53EF;&#x4EE5;&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF01;<code>:into</code> &#x63A5;&#x53D7;&#x5B9E;&#x73B0;&#x4E86; <code>Collectable</code> &#x534F;&#x8BAE;&#x7684;&#x4EFB;&#x4F55;&#x7ED3;&#x6784;&#x4F53;&#x3002;</p>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x7528; <code>:into</code> &#x4ECE;&#x5173;&#x952E;&#x5B57;&#x5217;&#x8868;&#x4E2D;&#x63A8;&#x5BFC;&#x51FA;&#x4E00;&#x4E2A;&#x6620;&#x5C04;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-keyword">for</span> {k, v} &lt;- [<span class="hljs-symbol">one:</span> <span class="hljs-number">1</span>, <span class="hljs-symbol">two:</span> <span class="hljs-number">2</span>, <span class="hljs-symbol">three:</span> <span class="hljs-number">3</span>], <span class="hljs-symbol">into:</span> %{}, <span class="hljs-symbol">do:</span> {k, v}
%{<span class="hljs-symbol">one:</span> <span class="hljs-number">1</span>, <span class="hljs-symbol">three:</span> <span class="hljs-number">3</span>, <span class="hljs-symbol">two:</span> <span class="hljs-number">2</span>}
</code></pre>
<p>&#x56E0;&#x4E3A;&#x4E8C;&#x8FDB;&#x5236;&#x4E5F;&#x662F;&#x53EF;&#x4EE5;&#x679A;&#x4E3E;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x63A8;&#x5BFC;&#x5F0F;&#x548C; <code>:into</code> &#x6765;&#x521B;&#x5EFA;&#x5B57;&#x7B26;&#x4E32;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; <span class="hljs-keyword">for</span> c &lt;- [<span class="hljs-number">72</span>, <span class="hljs-number">101</span>, <span class="hljs-number">108</span>, <span class="hljs-number">108</span>, <span class="hljs-number">111</span>], <span class="hljs-symbol">into:</span> <span class="hljs-string">&quot;&quot;</span>, <span class="hljs-symbol">do:</span> &lt;&lt;c&gt;&gt;
<span class="hljs-string">&quot;Hello&quot;</span>
</code></pre>
<p>&#x5C31;&#x8FD9;&#x4E48;&#x591A;&#x5185;&#x5BB9;&#xFF01;&#x5217;&#x8868;&#x63A8;&#x5BFC;&#x5F0F;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x7CBE;&#x786E;&#x5730;&#x904D;&#x5386;&#x96C6;&#x5408;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="testing.html" class="navigation navigation-prev " aria-label="Previous page: 测试">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="strings.html" class="navigation navigation-next " aria-label="Next page: 字符串">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"version":"1.1.1","title":"推导","level":"1.14","depth":1,"next":{"title":"字符串","level":"1.15","depth":1,"path":"lessons/basics/strings.md","ref":"lessons/basics/strings.md","articles":[]},"previous":{"title":"测试","level":"1.13","depth":1,"path":"lessons/basics/testing.md","ref":"lessons/basics/testing.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"lessons/basics/comprehensions.md","mtime":"2019-11-05T02:25:51.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-11-05T03:01:22.004Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

